<template>
    <mescroll-uni
        ref="mescrollRef"
        @init="mescrollInit"
        :height="height"
        :down="downOption"
        @down="downRefresh"
        :up="upOption"
        @up="getData">
        <order-item
            v-for="(item, index) in datas"
            :key="index"
            :swiperIndex="swiperIndex"
            :data="item"
            :checkIds="checkIds"
            @toggle="toggle"></order-item>
    </mescroll-uni>
</template>
<script>
import orderItem from "@/components/supplier/order/order-item.vue"

import { getUserOrderList } from "@/service/api/order.js"
export default {
    props: {
        height: {
            type: String,
            default: "100px",
        },
        state: {
            type: String,
            default: "-1",
        },
        requestData: {
            type: Object,
            default: {},
        },
        swiperIndex: {
            type: Number,
            default: -1,
        },
        initIds: {
            type: Boolean,
            default: false,
        },
    },
    components: {
        orderItem,
    },
    data() {
        return {
            datas: [],
            data: [],
            productList: [],
            param: {},
            downOption: {
                use: true,
            },
            checkIds: "",
        }
    },
    watch: {
        initIds(e) {
            this.checkIds = ""
            this.$forceUpdate()
            this.$emit("changeIds", this.checkIds)
        },
    },
    mounted() {
        //#ifndef MP
        this.refresh(this.requestData)
        //#endif
    },
    methods: {
        toggle(id) {
            // 选中-取消选中
            if (this.checkIds.indexOf(id + ",") > -1) {
                this.checkIds = this.checkIds.replace(id + ",", "")
            } else {
                this.checkIds = this.checkIds + (id + ",")
            }
            this.$emit("changeIds", this.checkIds)
        },
        //获取列表数据
        getData(page) {
            let param = this.param
            param.pageSize = page.size
            param.pageIndex = page.num
            param.orderState = this.state
            getUserOrderList(param).then((res) => {
                if (res.State == 1) {
                    this.mescroll.endBySize(res.Data.length, res.RecordAmout)
                    this.datas = this.datas.concat(res.Data)
                } else {
                    this.mescroll.endBySize(0, 0)
                }
            })
        },
        //刷新
        refresh(requestData) {
            this.downRefresh(requestData, true)
        },
        //刷新
        downRefresh(requestData, isSetParam = false) {
            this.datas = []
            if (isSetParam) {
                this.param = requestData
            }
            this.mescroll.resetUpScroll()
        },
    },
}
</script>

<style lang="scss"></style>
